package com.saltlux.tdd.algorithm;

import java.util.Comparator;

public class IndexFinder {

	public int findFirstGreater(String[] array, String newString,
			Comparator comparator) {
		int firstGreaterIndex = array.length;

		for (int i = 0; i < array.length; i++) {
			if (comparator.compare(newString, array[i]) < 0) {
				firstGreaterIndex = i;
				break;
			}
		}

		return firstGreaterIndex;
	}

	public int findCenter(final Object[] array, final int start, final int end) {
		int s = start;
		int e = end;
		if (s >= array.length)
			return -1;
		if (e >= array.length)
			e = array.length - 1;
		int result = (e + s) / 2 + (e + s) % 2;
		return result;
	}

}
